In [1]:
spins = input("How many times did you spin? (Enter a negative number for couter-clockwise spins) ")
# Need to ensure the direction of the spin is always correct.
# This works because of the definition of the modulo operator and what happens with
# negative numbers. Keep this in mind for the assignment for chapter 3.
degrees = (float(spins) * 360) % 360
print("You are facing", degrees, "degrees relative to north")
In [2]:
import turtle
wn = turtle.Screen() # creates a graphics window
alex = turtle.Turtle() # create a turtle named alex
alex.speed(1)
alex.shape('turtle')
for i in [0,1,2,3,4,5]:
alex.forward(150) # tell alex to move forward by 150 units
alex.left(85) # turn by 90 degrees
alex.forward(75)
## This won't run as expected with the notebook. Wait a moment for the window to be created.
wn.exitonclick()
The documentation for the module inside of Python can be found here: https://docs.python.org/3.6/library/turtle.html
In [1]:
# Copied from the documentation example. This is bad practice to do import * DO NOT DO IT!
from turtle import *
color('red', 'yellow')
begin_fill()
while True:
forward(200)
left(170)
if abs(pos()) < 1:
break
end_fill()
done()
In [8]:
for number in range(6, 0, -1):
print("I have", number, "cookies. Iím going to eat one.")
print('I ate all my cookies')
In [1]:
import turtle
wn = turtle.Screen()
wn.bgcolor("lightgreen")
tess = turtle.Turtle()
tess.color("blue")
tess.shape("turtle")
jim = turtle.Turtle()
jim.color("green")
jim.shape("turtle")
carl = turtle.Turtle()
carl.color("red")
carl.shape("turtle")
tess.up()
carl.up()
jim.up()
# Keep in mind for today's studio
for size in range(5, 60, 2): # start with size = 5 and grow by 2
tess.stamp() # leave an impression on the canvas
carl.stamp()
jim.stamp()
carl.forward(size + 10)
jim.forward(size)
tess.forward(size) # move tess along
carl.right(90)
jim.left(24)
tess.right(24) # and turn her
wn.exitonclick()
In [8]:
from math import sqrt
print(sqrt(24))
print(sqrt(25))
print(sqrt(-2))
In [4]:
import random
random.seed(5)
print(random.randint(0,10))
print(random.randint(0,10))
print(random.randint(0,10), '\n')
random.seed(5)
print(random.randint(0,10))
print(random.randint(0,10))
print(random.randint(0,10), '\n')
random.seed(5)
print(random.randint(0,10))
print(random.randint(0,10))
print(random.randint(0,10), '\n')
random.seed(5)
print(random.randint(0,10))
print(random.randint(0,10))
print(random.randint(0,10), '\n')
In [6]:
bottles_of_beer = 99
for bottle_number in range(bottles_of_beer, 0, -1):
print(bottle_number, "Bottles of Beer on the Wall")
print("Take one down pass it around")
In [ ]:
import turtle
import random
wn = turtle.Screen()
anaise = turtle.Turtle()
hour = 1
lines = 1
angle = 1
anaise.speed(0)
# Set the color mode so the mac is happy.
# wn.colormode(255)
#change starting point of line randomly
while lines < 200:
anaise.goto(random.randrange(50), random.randrange(50))
anaise.down()
angle = (random.randrange(360))
anaise.color(random.randrange(255),random.randrange(255),random.randrange(255))
anaise.pensize(random.randrange(11))
anaise.right(angle)
anaise.forward(random.randrange(100))
anaise.up()
#Count the number of times the loop occurs
lines = lines + 1
wn.exitonclick()
In [ ]: